package ll;

public class SalaryCalculator {
    // 五险一金扣除比例（示例值，可根据实际政策调整）
    private static final double HOUSING_FUND_RATE = 0.12;  // 公积金比例
    private static final double TAX_THRESHOLD = 5000.0;     // 个税起征点

    /**
     * 计算员工当月应发工资
     * @param employee 员工对象
     * @param workDays 当月应出勤天数
     * @return 应发工资总额
     */
    public double calculateGrossSalary(Employee employee, int workDays) {
        // 计算基本工资（按出勤天数折算）
        double dailyBase = employee.getBaseSalary() / workDays;
        double actualBase = dailyBase * employee.getAttendanceDays();

        // 应发工资 = 基本工资 + 绩效奖金
        return actualBase + employee.getPerformanceBonus();
    }

    /**
     * 计算员工当月实发工资（含个税扣除）
     * @param grossSalary 应发工资
     * @param socialInsurance 社保扣除额
     * @return 实发工资
     */
    public double calculateNetSalary(double grossSalary, double socialInsurance) {
        // 计算应纳税所得额
        double taxableIncome = grossSalary - socialInsurance - TAX_THRESHOLD;
        if (taxableIncome <= 0) return grossSalary - socialInsurance;

        // 个人所得税计算（简化的超额累进税率示例）
        double tax = 0;
        if (taxableIncome <= 3000) {
            tax = taxableIncome * 0.03;
        } else if (taxableIncome <= 12000) {
            tax = 3000 * 0.03 + (taxableIncome - 3000) * 0.1;
        } else if (taxableIncome <= 25000) {
            tax = 3000 * 0.03 + 9000 * 0.1 + (taxableIncome - 12000) * 0.2;
        }
        return grossSalary - socialInsurance - tax;
    }

    /**
     * 计算公积金扣除额（示例：基本工资的12%）
     * @param baseSalary 基本工资
     * @return 公积金扣除额
     */
    public double calculateHousingFund(double baseSalary) {
        return baseSalary * HOUSING_FUND_RATE;
    }
}
